<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="My.js"></script>
<script type="text/javascript">
  var key = 0
  function login()
  {
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
    }
    else {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.open("post","login",true);
    xmlhttp.onreadystatechange=function ()
    { if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
      json=eval("("+xmlhttp.responseText+ ")")
      if(json.code==200)
        location.href="enter.html"
      else if (json.code==100)
        alert("用户名或密码错误!")
      else if(json.code==300)
      {
        if (confirm("该账号已在其他设备登录："+json.message+" 是否要验证拿回?"))
          location.href="verify.html?"+json.uuid
        else
          alert("不要偷看别人信息!")
      }

    }
    }

    userID=document.getElementById("sno").value;
    pwd=document.getElementById("pwd").value;
    pwd=encodePwd(pwd,key);
    alert(pwd)
    xmlhttp.setRequestHeader("Content-type",
            "application/x-www-form-urlencoded");

    xmlhttp.send("stuID="+userID+"&pwd="+pwd);

  }

  function getVerify()
  {
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
    }
    else {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.open("get","getcode",false);
    xmlhttp.onreadystatechange=function ()
    { if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
      key=xmlhttp.responseText
      document.getElementById("verifycode").innerHTML=key
    }
    }
    xmlhttp.send();
  }

</script>
</head>
<body onload="getVerify()">
<div aglin="center">
  <h1>NJUPT登录系统</h1>
  <div>
    用户名：<input type="text" id="sno"/><br>
    密 码：<input type="password" id="pwd"/><br>
    验证 码：<input type="text" id="code"/><label onclick="getVerify()" id="verifycode"></label><br>
    <button onclick="login()">登录</button>
  </div>
</div>
</body>
</html>